package com.jingdianjichi.subject.infra.basic.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingdianjichi.subject.infra.basic.entity.SubjectInfo;
import com.jingdianjichi.subject.infra.basic.entity.SubjectInfoEs;
import com.jingdianjichi.subject.infra.basic.mapper.SubjectInfoDao;
import com.jingdianjichi.subject.infra.basic.service.SubjectInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.List;

/**
 * 题目信息表(SubjectInfo)表服务实现类
 *
 * @author makejava
 * @since 2025-07-13 16:54:22
 */
@Slf4j
@Service("subjectInfoService")
public class SubjectInfoServiceImpl implements SubjectInfoService {
    @Resource
    private SubjectInfoDao subjectInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SubjectInfo queryById(Long id) {
        return this.subjectInfoDao.queryById(id);
    }



    /**
     * 新增数据
     *
     * @param subjectInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectInfo insert(SubjectInfo subjectInfo) {
        this.subjectInfoDao.insert(subjectInfo);
        return subjectInfo;
    }

    /**
     * 修改数据
     *
     * @param subjectInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SubjectInfo update(SubjectInfo subjectInfo) {
        this.subjectInfoDao.update(subjectInfo);
        return this.queryById(subjectInfo.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.subjectInfoDao.deleteById(id) > 0;
    }

    @Override
    public List<SubjectInfo> querySubjectInfosBySubjectIds(SubjectInfo subjectInfo,List<Long> subjectIds, int offset, int limit) {
//        if(log.isInfoEnabled()){
//            log.info("启动querySubjectInfoBySubjectIds查询参数：{}",subjectInfo);
//        }
        //先将subjectIds作为参数传入查询方法
       List<SubjectInfo> result = subjectInfoDao.querySubjectInfosBySubjectIds(subjectInfo,subjectIds,offset,limit);
//        if(log.isInfoEnabled()){
//            log.info("结束querySubjectInfoBySubjectIds查询结果：{}",result);
//        }
        return result;

    }

    @Override
    public int querySubjectInfoNumBySubjectIds(SubjectInfo subjectInfo, List<Long> subjectIds) {
        return subjectInfoDao.querySubjectInfoNumBySubjectIds(subjectInfo,subjectIds);
    }
    @Override
    public SubjectInfoEs querySubjectInfoEsById(Long subjectId) {
       return subjectInfoDao.querySubjectInfoEs(subjectId);
    }
    @Override
    public Page<SubjectInfo> queryPageByCondition(Page<SubjectInfo> page,SubjectInfo subjectInfo,Long CategoryId,Long LabelId ) {
        return subjectInfoDao.queryPageByCondition(page,subjectInfo,CategoryId,LabelId);
    }
}
